package org.jsola.hr.helper;

import org.jsola.common.ClassKit;
import org.jsola.common.DateKit;
import org.jsola.common.SafeKit;
import org.jsola.hr.constant.ContractDateEnum;
import org.jsola.hr.constant.ContractStatusEnum;
import org.jsola.hr.constant.FileType;
import org.jsola.hr.dto.EmpPaperContractAddDTO;
import org.jsola.hr.dto.EmpPaperContractUpdateDTO;
import org.jsola.hr.entity.EmpPaperContractDO;
import org.jsola.hr.query.EmpPaperContractQuery;
import org.jsola.hr.service.IEmpPaperContractService;
import org.jsola.hr.vo.EmpPaperContractVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.Date;
import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 纸质合同
 *
 * @author zhr
 */
@Component
public class EmpPaperContractTestHelper extends BaseTestHelper {

    @Autowired
    private IEmpPaperContractService empPaperContractService;

    /**
     * 生成add测试数据
     * @return EmpPaperContractAddDTO
     */
    public EmpPaperContractAddDTO getEmpPaperContractAddDTO(){
        EmpPaperContractAddDTO empPaperContractAddDTO = new EmpPaperContractAddDTO();
        empPaperContractAddDTO.setCompanyId(getRandomValue("varchar",32));
        empPaperContractAddDTO.setEmpId(getRandomValue("varchar",32));
        empPaperContractAddDTO.setNumber(getRandomValue("varchar",50));
        empPaperContractAddDTO.setType(FileType.LABORCONTRACTLIMIT.getValue());
        empPaperContractAddDTO.setName(getRandomValue("varchar",255));
        empPaperContractAddDTO.setTimeLimit(SafeKit.getInteger(getRandomValue("tinyint",4)));
        empPaperContractAddDTO.setTimeLimitType(ContractDateEnum.YEAR.getValue());
        empPaperContractAddDTO.setStartTime((Date)ClassKit.getObjectValue(getRandomValue("datetime",0),"java.util.Date"));
        empPaperContractAddDTO.setEndTime((Date)ClassKit.getObjectValue(getRandomValue("datetime",0),"java.util.Date"));
        empPaperContractAddDTO.setCompanyName(getRandomValue("varchar",100));
        empPaperContractAddDTO.setStatus(ContractStatusEnum.IMPLEMENT.getValue());
        empPaperContractAddDTO.setSubscribeTime((Date)ClassKit.getObjectValue(getRandomValue("datetime",0),"java.util.Date"));
        empPaperContractAddDTO.setRemarks(getRandomValue("text",2147483647));
        empPaperContractAddDTO.setFile(getRandomValue("text",2147483647));
        return empPaperContractAddDTO;
    }


    /**
     * 生成update测试数据
     * @return EmpPaperContractUpdateDTO
     */
    public EmpPaperContractUpdateDTO getEmpPaperContractUpdateDTO(EmpPaperContractVO empPaperContractVO){
        return empPaperContractService.selectDOById(empPaperContractVO.getId(), SITE_ID).to(EmpPaperContractUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return EmpPaperContractQuery
     */
    public EmpPaperContractQuery getEmpPaperContractQuery() {
        EmpPaperContractQuery empPaperContractQuery = new EmpPaperContractQuery();
        List<EmpPaperContractDO> empPaperContractDOList = empPaperContractService.list(new EmpPaperContractDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(empPaperContractDOList)) {
            EmpPaperContractDO empPaperContractDO = empPaperContractDOList.get(0);
            empPaperContractQuery = empPaperContractDO.to(EmpPaperContractQuery.class);
            if (empPaperContractDO.getStartTime() != null) {
                empPaperContractQuery.setStartTimeStart(DateKit.getBeforeDay(empPaperContractDO.getStartTime(),-1));
                empPaperContractQuery.setStartTimeEnd(DateKit.getBeforeDay(empPaperContractDO.getStartTime(),1));
            }
            if (empPaperContractDO.getEndTime() != null) {
                empPaperContractQuery.setEndTimeStart(DateKit.getBeforeDay(empPaperContractDO.getEndTime(),-1));
                empPaperContractQuery.setEndTimeEnd(DateKit.getBeforeDay(empPaperContractDO.getEndTime(),1));
            }
            if (empPaperContractDO.getSubscribeTime() != null) {
                empPaperContractQuery.setSubscribeTimeStart(DateKit.getBeforeDay(empPaperContractDO.getSubscribeTime(),-1));
                empPaperContractQuery.setSubscribeTimeEnd(DateKit.getBeforeDay(empPaperContractDO.getSubscribeTime(),1));
            }
        }
        return empPaperContractQuery;
    }

    /**
     * 保存示例
     * @return EmpPaperContractVO
     */
    public EmpPaperContractVO saveEmpPaperContractExample(){
        EmpPaperContractAddDTO addDTO = this.getEmpPaperContractAddDTO();
        EmpPaperContractVO empPaperContractVO = empPaperContractService.save(addDTO,buildTokenUser());
        return empPaperContractVO;
    }


}

